package com.teacher.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teacher.common.CommonResult;
import com.teacher.common.JwtTokenUtil;
import com.teacher.mapper.DepartmentMapper;
import com.teacher.mapper.PermissionMapper;
import com.teacher.mapper.RoleMapper;
import com.teacher.pojo.dto.login.LoginDto;
import com.teacher.pojo.dto.teacher.TeacherAddDto;
import com.teacher.pojo.dto.teacher.TeacherGetByDeptDto;
import com.teacher.pojo.dto.teacher.TeacherUpdateDto;
import com.teacher.pojo.entity.BaseEntity;
import com.teacher.pojo.entity.PerTeacher;
import com.teacher.mapper.PerTeacherMapper;
import com.teacher.pojo.entity.Role;
import com.teacher.pojo.entity.RoleUser;
import com.teacher.pojo.enums.PermissionType;
import com.teacher.pojo.json.PermissionList;
import com.teacher.pojo.json.RoleList;
import com.teacher.pojo.vo.teacher.LoginVo;
import com.teacher.pojo.vo.teacher.TeacherGetVo;
import com.teacher.pojo.vo.teacher.UserInfoVo;
import com.teacher.security.entity.permission.MenuReturnVo;
import com.teacher.security.entity.permission.Meta;
import com.teacher.security.entity.permission.Permission;
import com.teacher.security.entity.security.RedisUserInfo;
import com.teacher.security.service.IRedisService;
import com.teacher.security.entity.permission.Roles;
import com.teacher.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zfm
 * @since 2021-06-15
 */
@Service
public class PerTeacherServiceImpl extends ServiceImpl<PerTeacherMapper, PerTeacher> implements IPerTeacherService {

    @Value("${jwt.expiration}")
    private Long expiration;

    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @Autowired
    private IRedisService iRedisService;

    @Autowired
    private HttpServletRequest httpServletRequest;

    @Autowired
    private IRoleService iRoleService;

    @Autowired
    private IPermissionService iPermissionService;

    @Autowired
    private IDepartmentService iDepartmentService;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private IRoleUserService iRoleUserService;

    @Autowired
    private IPerTeacherService iPerTeacherService;

    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private PermissionMapper permissionMapper;


    /**
     * 根据部门查询教师信息
     *
     * @param dto
     * @return
     */
    @Override
    public CommonResult<IPage<TeacherGetVo>> getByDepartmentId(TeacherGetByDeptDto dto) {
        IPage<TeacherGetVo> page = new Page<TeacherGetVo>(dto.getCurrentPage(), dto.getPageSize());
        dto.setDepartmentIds(new ArrayList<>());
        if (dto.getDepartmentId() != null) {
            // 递归查询id
            dto.setDepartmentIds(departmentMapper.getChildIdsByParentId(dto.getDepartmentId()));
            dto.getDepartmentIds().add(dto.getDepartmentId());
        }
        IPage<TeacherGetVo> userReturnVoList = baseMapper.getUserPages(page, dto);
        for (TeacherGetVo record : userReturnVoList.getRecords()) {
            List<RoleUser> roleUserList = iRoleUserService.list(new QueryWrapper<RoleUser>().lambda()
                    .eq(RoleUser::getTeacherKey, record.getTeacherKey()));
            if (roleUserList.size() == 0) {
                continue;
            }
            List<Role> roles = iRoleService.list(new QueryWrapper<Role>().lambda()
                    .select(Role::getName, BaseEntity::getId)
                    .in(BaseEntity::getId, roleUserList.stream().map(RoleUser::getRoleId).collect(Collectors.toList())));
            record.setRoleList(roles.stream().map(item -> String.valueOf(item.getId())).collect(Collectors.toList()));
            record.setRoleNameList(roles.stream().map(Role::getName).collect(Collectors.toList()));
        }
        return CommonResult.success(userReturnVoList);

    }

    /**
     * 更新用户信息
     *
     * @param dto
     * @return
     */
    @Override
    public CommonResult<String> updateInfo(TeacherUpdateDto dto) {
        PerTeacher perTeacher = new PerTeacher();
        BeanUtils.copyProperties(dto, perTeacher);

        RoleList roleList = new RoleList();
        if (roleList.getRoleList() == null) {
            roleList.setRoleList(new ArrayList<>());
        }
        // 删除用户角色表
        iRoleUserService.remove(new QueryWrapper<RoleUser>().lambda()
                .eq(RoleUser::getTeacherKey, dto.getTeacherKey()));
        List<RoleUser> roleUserList = new ArrayList<>();
        for (Long aLong : dto.getRoleList()) {
            RoleUser roleUser = new RoleUser();
            roleUser.setRoleId(aLong);
            roleUser.setTeacherKey(dto.getTeacherKey());
            roleUserList.add(roleUser);
        }
        // 添加
        iRoleUserService.saveBatch(roleUserList);
        perTeacher.setUpperDept(dto.getDepartmentId());
        if (StrUtil.isNotBlank(dto.getPassword())) {
            perTeacher.setPassword(passwordEncoder.encode(dto.getPassword()));
        }
        if (baseMapper.update(perTeacher, new UpdateWrapper<PerTeacher>().lambda()
                .eq(PerTeacher::getTeacherKey, dto.getTeacherKey())) == 1) {
            return CommonResult.success("更新成功");
        }
        return CommonResult.failed("更新失败");
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    @Override
    public CommonResult<UserInfoVo> getUserInfo() {
        String teacherKey = jwtTokenUtil.getUsernameByRequest(httpServletRequest);
        String info = iRedisService.get(teacherKey);
        RedisUserInfo redisUserInfo = JSONUtil.toBean(info, RedisUserInfo.class);
        UserInfoVo userInfovo = new UserInfoVo();
        userInfovo.setPermissions(redisUserInfo.getPermissionValue());
        PerTeacher perTeacher = this.getOne(new QueryWrapper<PerTeacher>().lambda()
                .eq(PerTeacher::getTeacherKey, jwtTokenUtil.getUsernameByRequest(httpServletRequest))
                .last("limit 1"));
        userInfovo.setUsername(perTeacher.getName());
        return CommonResult.success(userInfovo);
    }

    /**
     * 添加用户
     *
     * @param dto
     * @return
     */
    @Override
    public CommonResult<String> add(TeacherAddDto dto) {
        PerTeacher perTeacher = this.getOne(new QueryWrapper<PerTeacher>().lambda()
                .eq(PerTeacher::getTeacherKey, dto.getTeacherKey()).last("limit 1"));
        if (perTeacher != null) {
            return CommonResult.failed("工号已存在");
        }
        perTeacher = new PerTeacher();
        BeanUtils.copyProperties(dto, perTeacher);
        RoleList roleList = new RoleList();
        if (roleList.getRoleList() == null) {
            roleList.setRoleList(new ArrayList<>());
        }
        // 删除用户角色表
        iRoleUserService.remove(new QueryWrapper<RoleUser>().lambda()
                .eq(RoleUser::getTeacherKey, dto.getTeacherKey()));
        List<RoleUser> roleUserList = new ArrayList<>();
        for (Long aLong : dto.getRoleList()) {
            RoleUser roleUser = new RoleUser();
            roleUser.setRoleId(aLong);
            roleUser.setTeacherKey(dto.getTeacherKey());
            roleUserList.add(roleUser);
        }
        // 添加
        iRoleUserService.saveBatch(roleUserList);
        perTeacher.setUpperDept(dto.getDepartmentId());
        if (StrUtil.isNotBlank(dto.getPassword())) {
            perTeacher.setPassword(passwordEncoder.encode(dto.getPassword()));
        }
        if (baseMapper.insert(perTeacher) == 1) {
            return CommonResult.success("添加成功");
        }
        return CommonResult.success("添加失败");
    }

    @Override
    public CommonResult<String> exchangeRoles(Long roleId) {
        String json = iRedisService.get(jwtTokenUtil.getUsernameByRequest(httpServletRequest));
        if (json == null) {
            return CommonResult.failed("登陆失效");
        }
        RedisUserInfo redisUserInfo = JSONUtil.toBean(json, RedisUserInfo.class);
        for (Roles role : redisUserInfo.getRoleList()) {
            if (role.getId().equals(roleId)) {
                return CommonResult.success(changeRole(jwtTokenUtil.getUsernameByRequest(httpServletRequest), roleId));
            }
        }
        return CommonResult.failed("无该角色");
    }

    public String changeRole(String userKey, Long roleId) {
        String redisInfo = iRedisService.get(userKey);
        RedisUserInfo redisUserInfo = JSONUtil.toBean(redisInfo, RedisUserInfo.class);

        Role role = roleMapper.selectById(roleId);
        PermissionList permissions = JSONUtil.toBean(role.getPermission(), PermissionList.class);
        List<Permission> permissionList = permissionMapper.selectBatchIds(permissions.getPermissionList());
        // 菜单去重
        permissionList = permissionList.stream().distinct().collect(Collectors.toList());
        // 当前角色id
        redisUserInfo.setCurrentRoleId(roleId);
        // 当前角色名称
        redisUserInfo.setCurrentRoleName(role.getName());
        // 当前角色所包含的权限码
        redisUserInfo.setPermissionValue(permissionList.stream().map(Permission::getPermissionValue).filter(item -> !item.equals("")).collect(Collectors.toList()));
        // 菜单
        redisUserInfo.setAllMenu(permissionList);
        iRedisService.set(userKey, JSONUtil.toJsonStr(redisUserInfo));
        iRedisService.expire(userKey, expiration);
        return role.getName();
    }

    /**
     * 登录
     *
     * @param dto
     * @return
     */
    @Override
    public CommonResult<LoginVo> login(LoginDto dto) {


        PerTeacher perTeacher = baseMapper.selectOne(new QueryWrapper<PerTeacher>().lambda()
                .eq(PerTeacher::getTeacherKey, dto.getUsername()));

        if (perTeacher == null) {
            return CommonResult.failed("非法用户");
        }


        List<com.teacher.security.entity.permission.Permission> permissionList = new ArrayList<>();

        List<String> permissionValue = new ArrayList<>();


//        RoleList roleList = JSONUtil.toBean(perTeacher.getRoleInfo(), RoleList.class);
        List<RoleUser> roleList = iRoleUserService.list(new QueryWrapper<RoleUser>().lambda()
                .eq(RoleUser::getTeacherKey, perTeacher.getTeacherKey()));
        RedisUserInfo redisUserInfo = new RedisUserInfo();
        if (roleList.size() != 0) {
            // 查询有效角色
            List<Role> roles = iRoleService.list(new QueryWrapper<Role>().lambda()
                    .eq(Role::getStatus, true)
                    .in(BaseEntity::getId, roleList.stream().map(RoleUser::getRoleId).collect(Collectors.toList())));
            List<Roles> rolesInfos = new ArrayList();
            roles.forEach(role1 ->{
                Roles roleInfo = new Roles();
                BeanUtils.copyProperties(role1, roleInfo);
                rolesInfos.add(roleInfo); });
            redisUserInfo.setRoleList(rolesInfos);
            for (Role role : roles) {
                PermissionList permissions = JSONUtil.toBean(role.getPermission(), PermissionList.class);
                List<Permission> getPermission = iPermissionService.list(new QueryWrapper<Permission>().lambda()
                        .in(Permission::getId, permissions.getPermissionList()).orderByDesc(Permission::getSort));
                permissionList.addAll(getPermission);
            }

            // 获取权限码
            for (Permission permission : permissionList) {
                if (permission.getType().equals(PermissionType.BUTTON.getCode())) {
                    permissionValue.add(permission.getPermissionValue());
                }
            }

        }

        permissionList = permissionList.stream().distinct().collect(Collectors.toList());


        String token = jwtTokenUtil.generateToken(perTeacher.getTeacherKey());

        redisUserInfo.setToken(token);

        redisUserInfo.setPermissionValue(permissionValue);

        redisUserInfo.setAllMenu(permissionList);

        iRedisService.set(perTeacher.getTeacherKey(), JSONUtil.toJsonStr(redisUserInfo));
        iRedisService.expire(perTeacher.getTeacherKey(), expiration);
        LoginVo loginVo = new LoginVo();
        loginVo.setToken(token);
        loginVo.setPermissions(permissionValue);
        loginVo.setUsername(perTeacher.getName());

        if(redisUserInfo.getRoleList() != null && redisUserInfo.getRoleList().size() > 0) {
            String userName = changeRole(perTeacher.getTeacherKey(), redisUserInfo.getRoleList().get(0).getId());
            loginVo.setCurrentRoleName(userName);
        }
        if(StrUtil.isBlank(loginVo.getCurrentRoleName())) {
            loginVo.setCurrentRoleName("无角色权限");

        }
        return CommonResult.success(loginVo);
    }

    /**
     * 获取用户菜单
     *
     * @return
     */
    @Override
    public CommonResult<Object> getMenu() {
        RedisUserInfo redisUserInfo = JSONUtil.toBean(
                iRedisService.get(jwtTokenUtil.getUsernameByRequest(httpServletRequest)), RedisUserInfo.class);
        List<Permission> permissionList = redisUserInfo.getAllMenu();
        // menu
        List<MenuReturnVo> menuReturnVoList = new ArrayList<>();
        List<MenuReturnVo> oriMenuList = new ArrayList<>();
        for (Permission permission : permissionList) {
            MenuReturnVo menuReturnVo = new MenuReturnVo();
            BeanUtils.copyProperties(permission, menuReturnVo);
            menuReturnVo.setLabel(permission.getName());

            Meta meta = new Meta();
            meta.setTitle(menuReturnVo.getLabel());
            meta.setIcon(menuReturnVo.getIcon());
            meta.setHideMenu(!permission.getIsShow());
            menuReturnVo.setMeta(meta);

            if (StrUtil.isBlank(menuReturnVo.getComponent())) {
                menuReturnVo.setComponent("LAYOUT");
            }
            if (permission.getIsExt()) {
                meta.setFrameSrc(permission.getPath());
            }


            oriMenuList.add(menuReturnVo);
        }
        for (MenuReturnVo menuReturnVo : oriMenuList) {
            if (menuReturnVo.getType().equals(PermissionType.BUTTON.getCode())) {
                continue;
            }
            if (menuReturnVo.getParentId() == 0) {
                menuReturnVoList.add(menuReturnVo);
                continue;
            }
            for (MenuReturnVo returnVo : oriMenuList) {
                if (menuReturnVo.getParentId().equals(returnVo.getId())) {
                    if (returnVo.getChildren() == null) {
                        returnVo.setChildren(new ArrayList<>());
                    }
                    returnVo.getChildren().add(menuReturnVo);
                }
            }
        }

        String url = "[{\n" +
                "  label: \"缓冲\",\n" +
                "  path: '/cache',\n" +
                "  component: 'views/util/cache',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'cache',\n" +
                "    keepAlive: true\n" +
                "  },\n" +
                "  children: []\n" +
                "}, {\n" +
                "  label: \"参数\",\n" +
                "  path: '/params',\n" +
                "  component: 'views/util/params',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'params',\n" +
                "  },\n" +
                "}, {\n" +
                "  label: \"标签\",\n" +
                "  path: '/tags',\n" +
                "  component: 'views/util/tags',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'tags',\n" +
                "  },\n" +
                "  children: []\n" +
                "}, {\n" +
                "  label: \"存储\",\n" +
                "  path: '/store',\n" +
                "  component: 'views/util/store',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'store',\n" +
                "  },\n" +
                "  children: []\n" +
                "}, {\n" +
                "  label: \"日志监控\",\n" +
                "  path: '/logs',\n" +
                "  component: 'views/util/logs',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'logs',\n" +
                "  },\n" +
                "  children: []\n" +
                "}, {\n" +
                "  label: \"返回顶部\",\n" +
                "  path: '/top',\n" +
                "  component: 'views/util/top',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'top',\n" +
                "  },\n" +
                "  children: []\n" +
                "}, {\n" +
                "  label: \"图钉\",\n" +
                "  path: '/affix',\n" +
                "  component: 'views/util/affix',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'affix',\n" +
                "  },\n" +
                "  children: []\n" +
                "}, {\n" +
                "  label: '多级菜单',\n" +
                "  path: '/deep',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  children: [{\n" +
                "    label: '多级菜单1-1',\n" +
                "    path: 'deep',\n" +
                "    iconBgColor: randomColor(),\n" +
                "    children: [{\n" +
                "      label: '多级菜单2-1',\n" +
                "      path: 'deep',\n" +
                "      iconBgColor: randomColor(),\n" +
                "      component: 'views/util/deep',\n" +
                "    }]\n" +
                "  }]\n" +
                "}, {\n" +
                "  label: \"外部页面\",\n" +
                "  path: '/out',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'out',\n" +
                "  },\n" +
                "  children: [{\n" +
                "    label: \"官方网站(内嵌页面)\",\n" +
                "    path: 'website',\n" +
                "    href: 'https://avuejs.com',\n" +
                "    icon: 'icon-caidan',\n" +
                "    iconBgColor: randomColor(),\n" +
                "    meta: {\n" +
                "      i18n: 'website',\n" +
                "    }\n" +
                "  }, {\n" +
                "    label: \"全局函数(外链页面)\",\n" +
                "    path: 'api',\n" +
                "    href: 'https://avuejs.com/docs/api?test1=1&test2=2',\n" +
                "    icon: 'icon-caidan',\n" +
                "    iconBgColor: randomColor(),\n" +
                "    meta: {\n" +
                "      target: '_blank',\n" +
                "      i18n: 'api',\n" +
                "    }\n" +
                "  }]\n" +
                "}, {\n" +
                "  label: \"表格\",\n" +
                "  path: '/table',\n" +
                "  component: 'views/util/table',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'table',\n" +
                "  },\n" +
                "  children: []\n" +
                "}, {\n" +
                "  label: \"表单\",\n" +
                "  path: '/form',\n" +
                "  component: 'views/util/form',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'form'\n" +
                "  },\n" +
                "  children: []\n" +
                "}, {\n" +
                "  label: \"异常页\",\n" +
                "  path: '/error',\n" +
                "  meta: {\n" +
                "    i18n: 'error',\n" +
                "  },\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  children: [{\n" +
                "    label: \"error403\",\n" +
                "    path: 'error',\n" +
                "    component: 'components/error-page/403',\n" +
                "    icon: 'icon-caidan',\n" +
                "    iconBgColor: randomColor(),\n" +
                "    children: []\n" +
                "  }, {\n" +
                "    label: \"error404\",\n" +
                "    path: '404',\n" +
                "    component: 'components/error-page/404',\n" +
                "    icon: 'icon-caidan',\n" +
                "    iconBgColor: randomColor(),\n" +
                "    children: []\n" +
                "  }, {\n" +
                "    label: \"error500\",\n" +
                "    path: '500',\n" +
                "    component: 'components/error-page/500',\n" +
                "    icon: 'icon-caidan',\n" +
                "    iconBgColor: randomColor(),\n" +
                "    children: []\n" +
                "  }]\n" +
                "}, {\n" +
                "  label: \"关于\",\n" +
                "  path: '/about',\n" +
                "  component: 'views/util/about',\n" +
                "  icon: 'icon-caidan',\n" +
                "  iconBgColor: randomColor(),\n" +
                "  meta: {\n" +
                "    i18n: 'about',\n" +
                "  },\n" +
                "  children: []\n" +
                "}]";

        String url2 = "[\n" +
                "        {\n" +
                "            \"path\": \"/permission\",\n" +
                "            \"children\": [\n" +
                "                {\n" +
                "                    \"path\": \"user\",\n" +
                "                    \"component\": \"views/permission/user\",\n" +
                "                    \"children\": [],\n" +
                "                    \"meta\": {\n" +
                "                        \"keepAlive\": false\n" +
                "                    },\n" +
                "                    \"icon\": \"icon-yonghu\",\n" +
                "                    \"name\": \"教职工管理\",\n" +
                "                    \"label\": \"教职工管理\",\n" +
                "                    \"id\": \"1277862381913538561\",\n" +
                "                    \"type\": 1,\n" +
                "                    \"parentId\": \"1277847661961707521\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"path\": \"/menu\",\n" +
                "                    \"component\": \"views/permission/menu\",\n" +
                "                    \"children\": [],\n" +
                "                    \"meta\": {\n" +
                "                        \"keepAlive\": false\n" +
                "                    },\n" +
                "                    \"icon\": \"el-icon-menu\",\n" +
                "                    \"name\": \"菜单管理\",\n" +
                "                    \"label\": \"菜单管理\",\n" +
                "                    \"id\": \"1278159001125380098\",\n" +
                "                    \"type\": 1,\n" +
                "                    \"parentId\": \"1277847661961707521\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"path\": \"/role\",\n" +
                "                    \"component\": \"views/permission/role\",\n" +
                "                    \"children\": [],\n" +
                "                    \"meta\": {\n" +
                "                        \"keepAlive\": false\n" +
                "                    },\n" +
                "                    \"icon\": \"icon-yonghu3\",\n" +
                "                    \"name\": \"角色管理\",\n" +
                "                    \"label\": \"角色管理\",\n" +
                "                    \"id\": \"1277939380970868737\",\n" +
                "                    \"type\": 1,\n" +
                "                    \"parentId\": \"1277847661961707521\"\n" +
                "                },\n" +
                "                {\n" +
                "                    \"path\": \"/department\",\n" +
                "                    \"component\": \"views/permission/department\",\n" +
                "                    \"children\": [],\n" +
                "                    \"meta\": {\n" +
                "                        \"keepAlive\": false\n" +
                "                    },\n" +
                "                    \"icon\": \"icon-bumen1\",\n" +
                "                    \"name\": \"部门管理\",\n" +
                "                    \"label\": \"部门管理\",\n" +
                "                    \"id\": \"1278159409277296642\",\n" +
                "                    \"type\": 1,\n" +
                "                    \"parentId\": \"1277847661961707521\"\n" +
                "                }\n" +
                "            ],\n" +
                "            \"meta\": {\n" +
                "                \"keepAlive\": false\n" +
                "            },\n" +
                "            \"icon\": \"icon-quanxian\",\n" +
                "            \"name\": \"权限管理\",\n" +
                "            \"label\": \"权限管理\",\n" +
                "            \"id\": \"1277847661961707521\",\n" +
                "            \"type\": 1,\n" +
                "            \"parentId\": \"0\"\n" +
                "        }\n" +
                "    ]";

//        return CommonResult.success(new JSONArray(url2));
        String url3 = "{\n" +
                "    path: '/dashboard',\n" +
                "    name: 'Dashboard',\n" +
                "    component: '/dashboard/welcome/index',\n" +
                "    meta: {\n" +
                "      title: 'routes.dashboard.welcome',\n" +
                "      affix: true,\n" +
                "      icon: 'ant-design:home-outlined',\n" +
                "    },\n" +
                "  }";
//        menuReturnVoList.add(JSONUtil.toBean(url3,MenuReturnVo.class));
        return CommonResult.success(menuReturnVoList);
    }

    /**
     * 用户登出
     *
     * @return
     */
    @Override
    public CommonResult<String> logout() {
        iRedisService.remove(jwtTokenUtil.getUsernameByRequest(httpServletRequest));
        return CommonResult.success("退出成功");
    }
}
